package com.stud.framework.runner;

import com.stud.common.properties.LocalProperties;
import com.stud.common.constant.Constants;
import com.stud.system.service.SysCacheInitService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 系统启动时,初始化必要缓存
 * sys_cache_init.init_flag == 0,则执行初始化
 *
 * @author Stud
 */

@Component
@Order(3)
@Slf4j
@RequiredArgsConstructor
public class CacheInitRunner implements ApplicationRunner {

    private final SysCacheInitService cacheInitService;

    @Override
    public void run(ApplicationArguments args) {
        String master = LocalProperties.getProperty(Constants.MASTER);
        if (Objects.equals(Constants.MASTER_Y, master)) {
            cacheInitService.initCache();
        }
    }
}
